﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using MyWebPagesStarterKit.Utils;
using MyWebPagesStarterKit;
using System.Text;

public partial class EasyControls_ContactForm : System.Web.UI.UserControl
{
    protected void Send(object sender, EventArgs e)
    {
        int status;

        Dictionary<string, string> replacements = new Dictionary<string, string>();
        replacements.Add("<%Name%>", txtName.Text);
        replacements.Add("<%Email%>", txtEmail.Text);
        replacements.Add("<%Message%>", txtMessage.Text);
        replacements.Add("<%FavoriteCMS%>", txtFavoriteCms.Text);

        /*
            If you add a dropdown or other controls, just assaign them into the dictionary above.
            replacements.Add("<%FavColor%>", dropdown1.SelectedValue);
        */

        //Above fields has to added to EmailTemplates in administration 

        //EmailSender description
        //
        // Status tells if a message is sent
        //      0 = sent with no errors
        //      1 = failed sending email
        // The email address to send this email to
        // The UniqueTitle in MailTemplate to use
        // The dictionary of replacements (Above)
        EmailSender emailSender = new EmailSender(out status, WebSite.GetInstance().MailSenderAddress, "ContactForm", replacements);

        switch (status)
        {
            case 0:
                message.Text = EmailSender.StatusMessage(0); //Or make your own custom message
                formPanel.Visible = false;
                messagePanel.Visible = true;
                break;
            case 1:
                message.Text = EmailSender.StatusMessage(1);
                formPanel.Visible = true;
                messagePanel.Visible = true;
                break;
        }
    }
}
